<%= form_for @team_user, url: @team_user.new_record? ? user_team_users_path(@team) : user_team_user_path(@team, @team_user) do |f| %>
  <%= render "shared/error_messages", target: @team_user %>
  <% if @team_user.new_record? %>
    <div class="form-group">
      <%= f.label :login %>
      <%= f.text_field :login, class: "form-control" %>
    </div>
  <% else %>
    <div class="form-group">
      <div class="flex">
        <%= user_avatar_tag(@team_user.user, :sm) %>
        <div class="ml-2"><%= user_name_tag(@team_user.user) %></div>
      </div>
    </div>
  <% end %>
  <div class="form-group">
    <%= f.label :role %>
    <%= f.select :role, TeamUser.roles.keys, {}, class: "form-control" %>
  </div>
  <div class="form-actions md:justify-between">
    <% if @team_user.new_record? %>
      <%= f.submit t("teams.new_team_user"), class: "btn btn-primary btn-block", 'data-disable-with' => t("common.saving") %>
    <% else %>
      <%= f.submit t("common.save"), class: "btn btn-primary", 'data-disable-with' => t("common.saving") %>
      <%= link_to t('teams.delete_team_user'),
                      user_team_user_path(@team, @team_user),
                      data: { method: 'DELETE', confirm: t('teams.delete_team_user_confirm') },
                      class: 'btn btn-danger' %>
    <% end %>
  </div>
<% end %>
